package hot;

/**
 * @author lakersUp
 * @Classname
 * @Description
 * @Date 2022/3/23 9:44
 * @Version 1.0
 */
public class Hot234isPalindrome {
    public boolean isPalindrome(ListNode head){
        if(head==null){
            return false;
        }
//        ListNode dummyNode=new ListNode(-1);
//        dummyNode.next=head;
        ListNode slow=head;
        ListNode fast=head;
        while (fast!=null){
            slow=slow.next;
            fast=fast.next;
            if(fast!=null){
                fast=fast.next;
            }
        }
        ListNode curr=slow;
        ListNode pre=null;
        while (curr!=null){
            ListNode tmp=curr.next;
            curr.next=pre;
            pre=curr;
            curr=tmp;
        }
        while (pre!=null){
            if(pre.val!=head.val){
                return false;
            }
            pre=pre.next;
            head=head.next;
        }
        return true;
    }
}
